package 代码记录.指定公司代码练习记录.备战快手;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zx
 * @create 2023-05-13 12:06
 */
public class 两数之和 {
    public int[] twoSum(int[] nums, int target) {
        int[] res = new int[2];
        Map<Integer,Integer> map = new HashMap<>();
        for(int i = 0;i < nums.length;i++){
            if(map.containsKey(target - nums[i])){
                res[0] = map.get(target - nums[i]);
                res[1] = i;
            }else{
                map.put(nums[i],i);
            }
        }
        return res;
    }
}
